unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, BaseGrid, AdvGrid, StdCtrls;

type
  TForm1 = class(TForm)
    AdvGrid: TAdvStringGrid;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure FormShow(Sender: TObject);
    procedure AdvGridGetEditorType(Sender: TObject; ACol, ARow: Integer;
      var AEditor: TEditorType);
    procedure AdvGridCanEditCell(Sender: TObject; ARow, ACol: Integer;
      var CanEdit: Boolean);
    procedure AdvGridGetFloatFormat(Sender: TObject; ACol, ARow: Integer;
      var IsFloat: Boolean; var FloatFormat: String);
    procedure Button1Click(Sender: TObject);
    procedure AdvGridGetAlignment(Sender: TObject; ARow, ACol: Integer;
      var HAlign: TAlignment; var VAlign: TVAlignment);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    procedure SetInitialize;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
  SetInitialize;
end;

procedure TForm1.SetInitialize;
var
  I:Integer;
begin
  with AdvGrid do
  begin
    FloatingFooter.Visible:=True;
    FloatingFooter.FooterStyle:=fsFixedLastRow;
    FloatingFooter.ColumnCalc[1]:=acSUM;
    FloatingFooter.ColumnCalc[2]:=acSUM;
    FloatingFooter.ColumnCalc[3]:=acSUM;
    FloatingFooter.ColumnCalc[4]:=acSUM;
    ColCount:=10;

    for I:=1 to ColCount-1 do
    begin
      ColWidths[I]:=100;
    end;
  end;
end;

procedure TForm1.AdvGridGetEditorType(Sender: TObject; ACol, ARow: Integer;
  var AEditor: TEditorType);
begin
  //AEditor:=edNumeric;
end;

procedure TForm1.AdvGridCanEditCell(Sender: TObject; ARow, ACol: Integer;
  var CanEdit: Boolean);
begin
  CanEdit:=True;
end;

procedure TForm1.AdvGridGetFloatFormat(Sender: TObject; ACol,
  ARow: Integer; var IsFloat: Boolean; var FloatFormat: String);
begin
  FloatFormat:='%8.2n';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(AdvGrid.Cells[1,1]);
end;

procedure TForm1.AdvGridGetAlignment(Sender: TObject; ARow, ACol: Integer;
  var HAlign: TAlignment; var VAlign: TVAlignment);
begin
  {HAlign:=taRightJustify;
  if ACol=1 then
  begin
    HAlign:=taLeftJustify;
  end else
  if ACol=2 then
  begin
    HAlign:=taCenter;
  end else
  if ACol=3 then
  begin
    HAlign:=taRightJustify;
  end;  }
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  with AdvGrid do
  begin
    if Alignments[RealCol,RealRow]=taLeftJustify then
    begin
      ShowMessage('taLeftJustify');
    end else
    if Alignments[RealCol,RealRow]=taCenter then
    begin
      ShowMessage('TaCenter');
    end else
    if Alignments[RealCol,RealRow]=taRightJustify then
    begin
      ShowMessage('taRightJustify');
    end;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  C,R:Integer;
begin
  with AdvGrid do
  begin
    for C:=0 to ColCount-1 do
    begin
      for R:=1 to RowCount-1 do
      begin
        if C in [1..5] then
        begin
          Alignments[C,R]:=taLeftJustify;
        end else
        begin
          Alignments[C,R]:=taRightJustify;
        end;
      end;
    end;
  end;
end;

end.
